package com.d3works.apps.production.service;

import com.d3works.apps.base.db.Company;
import com.d3works.apps.base.db.Product;
import com.d3works.apps.production.db.BillOfMaterial;
import com.d3works.apps.production.db.TempBomTree;
import com.d3works.apps.sale.db.SaleOrderLine;
import com.d3works.exception.D3worksException;
import com.d3works.meta.CallMethod;
import com.google.inject.persist.Transactional;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

public interface BillOfMaterialService {

  static final String UNIT_MIN_CODE = "MIN";

  static final String UNIT_DAY_CODE = "JR";

  public List<BillOfMaterial> getBillOfMaterialSet(Product product);

  @Transactional(rollbackOn = {Exception.class})
  public void updateProductCostPrice(BillOfMaterial billOfMaterial) throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  public BillOfMaterial customizeBillOfMaterial(SaleOrderLine saleOrderLine)
      throws D3worksException;

  public BillOfMaterial generateNewVersion(BillOfMaterial billOfMaterial);

  public String getFileName(BillOfMaterial billOfMaterial);

  public String getReportLink(
      BillOfMaterial billOfMaterial, String name, String language, String format)
      throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  public TempBomTree generateTree(BillOfMaterial billOfMaterial, boolean useProductDefaultBom);

  @Transactional
  public void setBillOfMaterialAsDefault(BillOfMaterial billOfMaterial) throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  BillOfMaterial customizeBillOfMaterial(BillOfMaterial billOfMaterial) throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  BillOfMaterial customizeBillOfMaterial(BillOfMaterial billOfMaterial, int depth)
      throws D3worksException;

  String computeName(BillOfMaterial bom);

  void addRawMaterials(long billOfMaterialId, ArrayList<LinkedHashMap<String, Object>> rawMaterials)
      throws D3worksException;

  @CallMethod
  public BillOfMaterial getDefaultBOM(Product originalProduct, Company company)
      throws D3worksException;

  List<BillOfMaterial> getAlternativesBOM(Product originalProduct, Company company)
      throws D3worksException;

  /**
   * Returns all the products from boms
   *
   * @param companySet
   * @return
   * @throws D3worksException
   */
  List<Long> getBillOfMaterialProductsId(Set<Company> companySet) throws D3worksException;
}
